#!/usr/bin/perl -w

#====================================================================
# access_log2epstat
# File ID: af31d840-5d36-11df-aa67-90e6ba3022ac
# Konverterer access_log fra Apache til fil som passer til epstat(1).
# Langt og trasig navn, men nøye då.
#====================================================================

use strict;
use Time::Local;

# 194.248.216.3 - - [13/Aug/2001:16:04:37 +0200] "GET

my %mnd_hash = (
	'Jan'=>0, 'Feb'=>1, 'Mar'=>2, 'Apr'=>3, 'May'=>4,  'Jun'=>5,
	'Jul'=>6, 'Aug'=>7, 'Sep'=>8, 'Oct'=>9, 'Nov'=>10, 'Dec'=>11
);

while (<>) {
	if (m!
			\S+ # IP
			\s+
			\S+
			\s+
			\S+
			\s+
			\[
			(\d+) # Dato
			/
			(\S+) # Mnd
			/
			(\d{4}) # År
			:(\d\d):(\d\d):(\d\d) # Klokka
			\s+
			([+\-]\d\d)(\d\d)
		!x
		) {
			my ($Day, $Mon, $Year, $Hour, $Min, $Sec, $zone_hour, $zone_min) =
			   (  $1,   $2,    $3,    $4,   $5,   $6,         $7,        $8);
			my $num_mon = $mnd_hash{$Mon};
			my $Secs = timegm($Sec, $Min, $Hour, $Day, $num_mon, $Year);
			$Secs -= ($zone_hour*3600); # Vi driter i minuttene fir å få opp farta.
			print("$Secs\n");
		} else {
			print(STDERR "Ukjent linje $.\n");
		}
}

__END__
